GetChars(Int32,Int64,Char[],Int32,Int32) Method
On this page
Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.
Syntax
|
|---|
'Declaration
Public Overloads Overrides Function GetChars( _
ByVal As Integer, _
ByVal As Long, _
ByVal () As Char, _
ByVal As Integer, _
ByVal As Integer _
) As Long |
Parameters
- i
- The zero-based column ordinal.
- fieldOffset
- The index within the field where the read operation is to begin.
- buffer
- The buffer into which to copy data.
- bufferOffset
- The index within the buffer where the write operation is to begin.
- length
- The maximum number of characters to read.
Return Value
The actual number of characters read.
Example
This sample shows how to read data from a field into array of chars.
|
|---|
static void GetThatChars(DB2Connection db2Connection)
{
DB2Command cmd = new DB2Command("SELECT * FROM Dept");
cmd.Connection = db2Connection;
db2Connection.Open();
try
{
DB2DataReader reader = cmd.ExecuteReader();
reader.Read();
char[] myChars = new char[50];
long bytesRead = reader.GetChars(reader.GetOrdinal("DName"),0,myChars,0,50);
Console.WriteLine(bytesRead+ " bytes read from the table.");
Console.WriteLine(myChars);
reader.Close();
}
finally
{
db2Connection.Close();
}
} |
|
|---|
Public Sub GetThatChars(ByVal db2Connection As DB2Connection)
Dim cmd As DB2Command = New DB2Command("SELECT * FROM Dept")
cmd.Connection = db2Connection
db2Connection.Open()
Try
Dim reader As DB2DataReader = cmd.ExecuteReader()
reader.Read()
Dim myChars(50) As Char
Dim bytesRead As Long = reader.GetChars(reader.GetOrdinal("DName"), 0, myChars, 0, 50)
Console.WriteLine(bytesRead & " bytes read from the table.")
Console.WriteLine(myChars)
reader.Close()
Finally
db2Connection.Close()
End Try
End Sub |
See Also